<?php
$menumark = 'order_sta';
switch ($act) {
    //#####################@ 修改分类 @#####################//
    case 'ordersta_detail_today':
        $start_time = date('Y-m-d H:i:s', strtotime(date('Y-m-d', time()) . ' 00:00:00'));  //当天开始时间
        $end_time = date('Y-m-d H:i:s', strtotime(date("Y-m-d") . ' 24:00:00')); //当天结束时间
        $sql = "select * from wxgg_order where order_subdate >   '$start_time'  and order_subdate <  '$end_time'";
        $order = $db->sql_selectall($sql);
        foreach ($order as $k => $v) {
            $house = $db->pe_select('house', array('house_id' => $v['order_houseid']));
            $order[$k]['order_housename'] = $house['house_name'];
        }

        include(pe_tpl('order_list.html'));
        break;

    case 'ordersta_detail_week':
        //当前日期
        $sdefaultDate = date("Y-m-d");
        //$first =1 表示每周星期一为开始日期 0表示每周日为开始日期
        $first = 1;
        //获取当前周的第几天 周日是 0 周一到周六是 1 - 6
        $w = date('w', strtotime($sdefaultDate));
        //获取本周开始日期，如果$w是0，则表示周日，减去 6 天
        $week_start = date('Y-m-d H:i:s', strtotime("$sdefaultDate -" . ($w ? $w - $first : 6) . ' days'));
        //本周结束日期
        $week_end = date('Y-m-d H:i:s', strtotime("$week_start +6 days"));

        $sql = "select * from wxgg_order where order_subdate >   '$week_start'  and order_subdate <  '$week_end'";
        $order = $db->sql_selectall($sql);
        foreach ($order as $k => $v) {
            $house = $db->pe_select('house', array('house_id' => $v['order_houseid']));
            $order[$k]['order_housename'] = $house['house_name'];
        }

        include(pe_tpl('order_list.html'));
        break;

    case 'ordersta_detail_month':
        //获取本月开始的时间戳
        $beginThismonth = date('Y-m-d H:i:s', mktime(0, 0, 0, date('m'), 1, date('Y')));
        //获取本月结束的时间戳
        $endThismonth = date('Y-m-d H:i:s', mktime(23, 59, 59, date('m'), date('t'), date('Y')));

        $sql = "select * from wxgg_order where order_subdate >   '$beginThismonth'  and order_subdate <  '$endThismonth'";


        $order = $db->sql_selectall($sql);
        foreach ($order as $k => $v) {
            $house = $db->pe_select('house', array('house_id' => $v['order_houseid']));
            $order[$k]['order_housename'] = $house['house_name'];
        }

        include(pe_tpl('order_list.html'));
        break;

    case 'find':
        $start_time = strtotime($_g_in_date) ? strtotime($_g_in_date) : "";
        $end_time = strtotime($_g_out_date) ? strtotime($_g_out_date) : "";

        if (empty($start_time) || empty($end_time)) {

            pe_error('请选择统计时间', 'admin.php?mod=order_sta');
        } else {

            $sql = "select *  from wxgg_order where    order_startdate >= " . $start_time . " and order_startdate <= " . $end_time;
        }

        $order = $db->sql_selectall($sql);
        if (count($order) > 0) {
            foreach ($order as $k => $v) {
                $house = $db->pe_select('house', array('house_id' => $v['order_houseid']));
                $order[$k]['order_housename'] = $house['house_name'];
                $order_allmoney = $order_allmoney + $v['order_endprice'];
            }

        }

        $order_amount = count($order);//订单总数

        include(pe_tpl('ordersta_time.html'));




        break;


        //统计时间段内的订单
    case 'ordersta_time_detail':
        $start_time = strtotime($_g_in_date) ? strtotime($_g_in_date) : "";
        $end_time = strtotime($_g_out_date) ? strtotime($_g_out_date) : "";

        $sql = "select * from wxgg_order where order_subdate >   '$start_time'  and order_subdate <  '$end_time'";


        $order = $db->sql_selectall($sql);
        foreach ($order as $k => $v) {
            $house = $db->pe_select('house', array('house_id' => $v['order_houseid']));
            $order[$k]['order_housename'] = $house['house_name'];
        }
        include(pe_tpl('order_list.html'));
        break;

    case 'order_detail':
        $order = $db->pe_select('order', array('order_id' => $_g_id));
        foreach ($order as $k => $v) {
            $house = $db->pe_select('house', array('house_id' => $order['order_houseid']), 'house_name');

            $order['house_name'] = $house['house_name'];
//            mp($order);exit;
        }
        include(pe_tpl('order_detail.html'));
        break;


    //#####################@ 分类列表 @#####################//
    default :
        //本日
        $start_time = date('Y-m-d H:i:s', strtotime(date('Y-m-d', time()) . ' 00:00:00'));  //当天开始时间
        $end_time = date('Y-m-d H:i:s', strtotime(date("Y-m-d") . ' 24:00:00')); //当天结束时间
        $sql = "select * from wxgg_order where order_subdate >   '$start_time'  and order_subdate <  '$end_time'";
        $today_order = $db->sql_selectall($sql);
        $today_order_allmoney = 0;
        if (count($today_order) > 0)
            foreach ($today_order as $k => $v) {
                {
                    $house = $db->pe_select('house', array('house_id' => $v['order_houseid']));
                    $today_order[$k]['order_housename'] = $house['house_name'];
                    $today_order_allmoney = $today_order_allmoney + $v['order_endprice'];
                }
            }
        $today_order_amount = count($today_order);//订单总数
        //本日结束


        //本周
        $sdefaultDate = date("Y-m-d"); //当前日期
        //$first =1 表示每周星期一为开始日期 0表示每周日为开始日期
        $first = 1;
        //获取当前周的第几天 周日是 0 周一到周六是 1 - 6
        $w = date('w', strtotime($sdefaultDate));
        //获取本周开始日期，如果$w是0，则表示周日，减去 6 天
        $week_start = date('Y-m-d H:i:s', strtotime("$sdefaultDate -" . ($w ? $w - $first : 6) . ' days'));
        //本周结束日期
        $week_end = date('Y-m-d H:i:s', strtotime("$week_start +6 days"));

        $sql = "select * from wxgg_order where order_subdate >   '$week_start'  and order_subdate <  '$week_end'";
        $week_order = $db->sql_selectall($sql);
        if (count($week_order) > 0) {
            foreach ($week_order as $k => $v) {
                $house = $db->pe_select('house', array('house_id' => $v['order_houseid']));
                $week_order[$k]['order_housename'] = $house['house_name'];
                $week_order_allmoney = $week_order_allmoney + $v['order_endprice'];
            }
        }
        $week_order_amount = count($week_order);//订单总数
        //本周结束

        //本月
        //获取本月开始的时间戳
        $beginThismonth = date('Y-m-d H:i:s', mktime(0, 0, 0, date('m'), 1, date('Y')));
        //获取本月结束的时间戳
        $endThismonth = date('Y-m-d H:i:s', mktime(23, 59, 59, date('m'), date('t'), date('Y')));

        $sql = "select * from wxgg_order where order_subdate >   '$beginThismonth'  and order_subdate <  '$endThismonth'";

        $month_order['order_allmoney'] = 0;
        $month_order = $db->sql_selectall($sql);
        if (count($month_order) > 0) {
            foreach ($month_order as $k => $v) {
                $house = $db->pe_select('house', array('house_id' => $v['order_houseid']));
                $month_order[$k]['order_housename'] = $house['house_name'];
                $month_order_allmoney = $month_order_allmoney + $v['order_endprice'];
            }
        }
        $month_order_amount = count($month_order);//订单总数
        //本月结束
        include(pe_tpl('ordersta_list.html'));

        break;
}
?>


